/*
 * @Copyright: CS of BIT
 * @Author: 王占坤
 * @File name: 
 * @Version: 
 * @Date: 2019-09-01 10:03:32 +0800
 * @LastEditTime: 2019-11-16 16:28:36 +0800
 * @LastEditors: 
 * @Description: 
 */
#ifndef __SOCKET_H__
#define __SOCKET_H__
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <error.h>
#include <sys/unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <assert.h>
#include <math.h>
typedef int socketfd;

class Socket //通信相关
{

public:
    char data_[1024];

protected:
    //SOCK_STREAM是TCP模式，SOCK_DGRAM是UDP模式
    int mode_;
    int port_;
    char ip_[100];
    int protocol_;
    int BUFFER_SIZE = 1024;

protected:
    void initialzeSocketaddr(struct sockaddr_in *addr, char *ip_addr);
    socketfd createSocket();

private:
    void reUse(socketfd &);

public:
    Socket(int sock_stream, int port, char *ip_addr);
    ~Socket();

    int receiveMSG(socketfd skf, size_t n_bytes, int flag = 0);
    int sendMSG(int skf, char *buff, size_t n_bytes, int flag = 0);
};

#endif